﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d101Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d101_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d101Mgr mgr = new d101Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_d101(e.Parameters[d101_Filter.ParamPrefix]));
            IList<d101> list = mgr.FindAllByPage_d101(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d101_Filter.ParamPrefix]);
            d101_MainStore.DataSource = list;
            d101_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d101Mgr mgr = new d101Mgr();
            RowSelectionModel sm = d101_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d101 _d101 = new d101();
                _d101.jgdm = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d101(_d101))
                {
                    log.Debug("d101中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d101_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d101Mgr mgr = new d101Mgr();
            d101 _d101 = new d101();
            if (Hid.Text.Length > 0)
                _d101 = mgr.FindById_d101(int.Parse(Hid.Text));
            
			_d101.jgmc = Txtjgmc.Text.Trim();
			_d101.zjdm = Txtzjdm.Text.Trim();
			_d101.dsgx = Txtdsgx.Text.Trim();
			_d101.zpdw = Txtzpdw.Text.Trim();
			_d101.jjlx = Txtjjlx.Text.Trim();
			_d101.jglb = Txtjglb.Text.Trim();
			_d101.jgjb = Txtjgjb.Text.Trim();
			_d101.shyl = Txtshyl.Text.Trim();
			_d101.tsdz = Txttsdz.Text.Trim();
			_d101.yzbm = Txtyzbm.Text.Trim();
			_d101.dhhm = Txtdhhm.Text.Trim();
			_d101.dzyx = Txtdzyx.Text.Trim();
			_d101.clsj = Txtclsj.Text.Trim();
			_d101.hddb = Txthddb.Text.Trim();
			_d101.zzzj = Txtzzzj.Text.Trim();
			_d101.wsgs = Txtwsgs.Text.Trim();
			_d101.ycws = Txtycws.Text.Trim();
			_d101.scws = Txtscws.Text.Trim();
			_d101.rs = Txtrs.Text.Trim();
			_d101.wjrs = Txtwjrs.Text.Trim();
			_d101.kssl = Txtkssl.Text.Trim();
			_d101.ssdq = Txtssdq.Text.Trim();
			_d101.mzrs = Txtmzrs.Text.Trim();
			_d101.chmzs = Txtchmzs.Text.Trim();
			_d101.ncys = Txtncys.Text.Trim();
			_d101.chcys = Txtchcys.Text.Trim();
			_d101.nsr = Txtnsr.Text.Trim();
			_d101.chnsr = Txtchnsr.Text.Trim();
			_d101.sblx = Txtsblx.Text.Trim();
			_d101.pzlx = Txtpzlx.Text.Trim();
			_d101.pybm = Txtpybm.Text.Trim();
			_d101.wbbm = Txtwbbm.Text.Trim();
			_d101.qtbm = Txtqtbm.Text.Trim();
			_d101.gldm = Txtgldm.Text.Trim();
			_d101.pzdm = Txtpzdm.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d101(_d101);
            else
                isok = mgr.Add_d101(_d101);
            if (isok)
            {
                d101_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d101中执行了保存（插入或修改），并成功");
                d101_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}